package com.hue.gulimailcart.vo;

import java.math.BigDecimal;
import java.util.List;

/**
 * @Author: 姚凤桥
 * @Date: 2021/12/4 17:13
 * @Description: 购物车
 */
public class Cart {
    /**
     * 所有购物项
     */
    private List<CartItem> cartItems;

    /**
     * 商品总数量
     */
    private Integer totalCount;

    /**
     * 商品种数
     */
    private Integer totalType;

    /**
     * 总价格
     */
    private BigDecimal totalPrice = new BigDecimal(0);

    /**
     * 优惠的价格，默认优惠为0.00
     */
    private BigDecimal reduce = new BigDecimal("0");

    public List<CartItem> getCartItems() {
        return cartItems;
    }

    public void setCartItems(List<CartItem> cartItems) {
        this.cartItems = cartItems;
    }

    public Integer getTotalCount() {
        if (cartItems != null && cartItems.size() > 0) {
            for (CartItem cartItem : cartItems) {
                totalCount += cartItem.getCount();
            }
        }
        return totalCount;
    }

    public void setTotalCount(Integer totalCount) {
        this.totalCount = totalCount;
    }

    public Integer getTotalType() {
        if (cartItems != null && cartItems.size() > 0) {
            totalType = cartItems.size();
        }
        return totalType;
    }

    public void setTotalType(Integer totalType) {
        this.totalType = totalType;
    }

    public BigDecimal getTotalPrice() {
        //获取商品总价
        if (cartItems != null && cartItems.size() > 0) {
            for (CartItem cartItem : cartItems) {
                if (cartItem.getCheck()) {
                    totalPrice = totalPrice.add(cartItem.getTotalPrice());
                }
            }
        }
        //减去优惠的价格
        return totalPrice.subtract(reduce);
    }

    public void setTotalPrice(BigDecimal totalPrice) {
        this.totalPrice = totalPrice;
    }

    public BigDecimal getReduce() {
        return reduce;
    }

    public void setReduce(BigDecimal reduce) {
        this.reduce = reduce;
    }
}
